﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OnHook.Business.Options;

namespace OnHook.Business.IServices.Common
{
    /// <summary>
    /// Redis 缓存
    /// </summary>
    public interface IRedisCacheService
    {

        #region GET方法
        /// <summary>
        /// get
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        object Get(string key);

        /// <summary>
        /// 取缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 获取缓存（字符串）
        /// </summary>
        /// <param name="key">缓存key</param>
        /// <returns></returns>
        string StringGet(string key);

        /// <summary>
        /// 获取缓存（Hash）
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="datakey"></param>
        /// <returns></returns>
        T HashGet<T>(string key, string datakey);

        /// <summary>
        /// 获取配置
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetSetting(string key);

        /// <summary>
        /// 获取配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        T GetSetting<T>(string key);

        #endregion

        #region Set方法

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="minutes">失效时间（单位分钟）</param>
        bool Set<T>(string key, T value, int minutes = 5);

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="expireTime">过期时间</param>
        /// <returns></returns>
        bool Set<T>(string key, T value, DateTime expireTime);

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="minutes">失效时间（单位分钟）</param>
        bool Set(string key, object value, int minutes = 5);

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="expireTime">过期时间</param>
        /// <returns></returns>
        bool Set(string key, object value, DateTime expireTime);
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireTime"></param>
        /// <returns></returns>
        bool StringSet(string key, string value, DateTime expireTime);

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="minutes"></param>
        /// <returns></returns>
        bool StringSet(string key, string value, int minutes = 5);

        /// <summary>
        /// HashSet方法
        /// </summary>
        /// <typeparam name="T">泛型T</typeparam>
        /// <param name="key">保存key</param>
        /// <param name="datakey">数据Key</param>
        /// <param name="value">数据值</param>
        /// <returns></returns>
        bool HashSet<T>(string key, string datakey, T value);

        #endregion

        /// <summary>
        /// 检查是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool IsExist(string key);

        /// <summary>
        /// 自增
        /// </summary>
        /// <returns></returns>
        Task<long> Increment();
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        Task<T> GetAppSettingAsync<T>() where T : IDbOption;
    }
}
